#include "reposelfupdatedialog.h"
#include "ui_reposelfupdatedialog.h"

#include <QDir>
#include <qd.h>

RepoSelfUpdateDialog::RepoSelfUpdateDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::RepoSelfUpdateDialog)
{
    ui->setupUi(this);

    connect(&m_process, qOverload<int>(&QProcess::finished), this, [this](int exitCode)
    {
        // close();
    });
    connect(&m_process, &QProcess::readyRead, this, [this]()
    {
        QString output = m_process.readAll();
        ui->git_pull_content->appendPlainText(output);
    });
}

RepoSelfUpdateDialog::~RepoSelfUpdateDialog()
{
    delete ui;
}

void RepoSelfUpdateDialog::setWorkdir(const QString &newWorkdir)
{
    m_workdir = newWorkdir;
}

void RepoSelfUpdateDialog::start()
{
    qd;
    m_process.setProgram("git");
    m_process.setArguments(QStringList("pull"));
    m_process.setWorkingDirectory(m_workdir + QDir::separator() + ".repo/repo");
    m_process.start();
}
